home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / cvs-1_3.lha / cvs-1.3 / lib / error.c < prev    next >
C/C++ Source or Header  |  1992-03-31  |  5KB  |  194 lines

  1. /* error.c -- error handler for noninteractive utilities
  2.    Copyright (C) 1990-1992 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* David MacKenzie */
  19. /* Brian Berliner added support for CVS */
  20.  
  21. #ifndef lint
  22. static char rcsid[] = "@(#)error.c 1.9 92/03/31";
  23. #endif /* not lint */
  24.  
  25. #include <stdio.h>
  26.  
  27. /* turn on CVS support by default, since this is the CVS distribution */
  28. #define    CVS_SUPPORT
  29.  
  30. #ifdef CVS_SUPPORT
  31. #if __STDC__
  32. void Lock_Cleanup(void);
  33. #else
  34. void Lock_Cleanup();
  35. #endif /* __STDC__ */
  36. #endif /* CVS_SUPPORT */
  37.  
  38. #ifndef VPRINTF_MISSING
  39.  
  40. #if __STDC__
  41. #include <stdarg.h>
  42. #define VA_START(args, lastarg) va_start(args, lastarg)
  43. #else
  44. #include <varargs.h>
  45. #define VA_START(args, lastarg) va_start(args)
  46. #endif
  47.  
  48. #else
  49.  
  50. #ifndef DOPRNT_MISSING
  51. #define va_alist args
  52. #define va_dcl int args;
  53. #else
  54. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  55. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  56. #endif
  57.  
  58. #endif
  59.  
  60. #ifdef STDC_HEADERS
  61. #include <stdlib.h>
  62. #include <string.h>
  63. #else
  64. #if __STDC__
  65. void exit(int status);
  66. #else
  67. void exit ();
  68. #endif /* __STDC__ */
  69. #endif
  70.  
  71. #ifdef STRERROR_MISSING
  72. static char *
  73. strerror (errnum)
  74.      int errnum;
  75. {
  76.   extern char *sys_errlist[];
  77.   extern int sys_nerr;
  78.  
  79.   if (errnum > 0 && errnum < sys_nerr)
  80.     return sys_errlist[errnum];
  81.   return "Unknown system error";
  82. }
  83. #endif /* STRERROR_MISSING */
  84.  
  85. /* Print the program name and error message MESSAGE, which is a printf-style
  86.    format string with optional args.
  87.    If ERRNUM is nonzero, print its corresponding system error message.
  88.    Exit with status STATUS if it is nonzero. */
  89. /* VARARGS */
  90. void
  91. #if !defined (VPRINTF_MISSING) && __STDC__
  92. error (int status, int errnum, char *message, ...)
  93. #else
  94. error (status, errnum, message, va_alist)
  95.      int status;
  96.      int errnum;
  97.      char *message;
  98.      va_dcl
  99. #endif
  100. {
  101.   extern char *program_name;
  102. #ifdef CVS_SUPPORT
  103.   extern char *command_name;
  104. #endif
  105. #ifndef VPRINTF_MISSING
  106.   va_list args;
  107. #endif
  108.  
  109. #ifdef CVS_SUPPORT
  110.   if (command_name && *command_name)
  111.     if (status)
  112.       fprintf (stderr, "%s [%s aborted]: ", program_name, command_name);
  113.     else
  114.       fprintf (stderr, "%s %s: ", program_name, command_name);
  115.   else
  116.     fprintf (stderr, "%s: ", program_name);
  117. #else
  118.   fprintf (stderr, "%s: ", program_name);
  119. #endif
  120. #ifndef VPRINTF_MISSING
  121.   VA_START (args, message);
  122.   vfprintf (stderr, message, args);
  123.   va_end (args);
  124. #else
  125. #ifndef DOPRNT_MISSING
  126.   _doprnt (message, &args, stderr);
  127. #else
  128.   fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  129. #endif
  130. #endif
  131.   if (errnum)
  132.     fprintf (stderr, ": %s", strerror (errnum));
  133.   putc ('\n', stderr);
  134.   fflush (stderr);
  135.   if (status)
  136.     {
  137. #ifdef CVS_SUPPORT
  138.       Lock_Cleanup();
  139. #endif
  140.       exit (status);
  141.     }
  142. }
  143.  
  144. #ifdef CVS_SUPPORT
  145.  
  146. /* Print the program name and error message MESSAGE, which is a printf-style
  147.    format string with optional args to the file specified by FP.
  148.    If ERRNUM is nonzero, print its corresponding system error message.
  149.    Exit with status STATUS if it is nonzero. */
  150. /* VARARGS */
  151. void
  152. #if !defined (VPRINTF_MISSING) && __STDC__
  153. fperror (FILE *fp, int status, int errnum, char *message, ...)
  154. #else
  155. fperror (fp, status, errnum, message, va_alist)
  156.      FILE *fp;
  157.      int status;
  158.      int errnum;
  159.      char *message;
  160.      va_dcl
  161. #endif
  162. {
  163.   extern char *program_name;
  164. #ifndef VPRINTF_MISSING
  165.   va_list args;
  166. #endif
  167.  
  168.   fprintf (fp, "%s: ", program_name);
  169. #ifndef VPRINTF_MISSING
  170.   VA_START (args, message);
  171.   vfprintf (fp, message, args);
  172.   va_end (args);
  173. #else
  174. #ifndef DOPRNT_MISSING
  175.   _doprnt (message, &args, fp);
  176. #else
  177.   fprintf (fp, message, a1, a2, a3, a4, a5, a6, a7, a8);
  178. #endif
  179. #endif
  180.   if (errnum)
  181.     fprintf (fp, ": %s", strerror (errnum));
  182.   putc ('\n', fp);
  183.   fflush (fp);
  184.   if (status)
  185.     {
  186. #ifdef CVS_SUPPORT
  187.       Lock_Cleanup();
  188. #endif
  189.       exit (status);
  190.     }
  191. }
  192.  
  193. #endif /* CVS_SUPPORT */
  194.